﻿using OSSUtility.Device;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ozone.Device
{
    //润泽八通切换阀
    public class DevSV08 : DevBase
    {

        //COM
        public DevSV08(int CommType, string FSrvIP, int FPort) : base(CommType, FSrvIP, FPort)
        {
            
        }

        public bool SwitchValve(int nValveNO)
        {

            //CC 00 44 01 00 DD EE 01
            byte[] bytesData = new byte[] { 0xCC,0x00,0x44,0x01,0x00,0xDD,0xEE,0x01 }; 

            if(nValveNO == 1)
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x01, 0x00, 0xDD, 0xEE, 0x01 };

            if (nValveNO == 2)
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x02, 0x00, 0xDD, 0xEF, 0x01 };

            if (nValveNO == 3)
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x03, 0x00, 0xDD, 0xF0, 0x01 };
 

            if (nValveNO == 4)
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x04, 0x00, 0xDD, 0xF1, 0x01 };

            if (nValveNO == 5)
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x05, 0x00, 0xDD, 0xF2, 0x01 };

            if (nValveNO == 6)
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x06, 0x00, 0xDD, 0xF3, 0x01 };

            if (nValveNO == 7)
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x07, 0x00, 0xDD, 0xF4, 0x01 };

            if (nValveNO == 8)
                bytesData = new byte[] { 0xCC, 0x00, 0x44, 0x08, 0x00, 0xDD, 0xF5, 0x01 };


            byte[] RecvData = session_.sendAndReadByte(bytesData);

            if (RecvData == null)
                return false;

            if (RecvData.Length != 8)
                return false;

            return true;
        }
    }
}
